This invention relates generally to disk caching techniques for computer systems and, more particularly, to techniques for managing cache memory for use in disk write operations. Rotating magnetic disks have become firmly established as reliable and relatively inexpensive devices for the storage of large amounts of data in computer systems. The principal drawback of disk storage devices is a relatively long delay between the time a disk operation is initiated and the time it is completed. This delay includes a seek latency during which the read/write heads are moved to a desired track or cylinder on a disk, and an additional rotational latency during which the disk rotates until a desired storage sector is under magnetic read/write heads. A disk drive usually has multiple recording surfaces, referred to as platters. A "cylinder" refers to a group of tracks, one on each platter, located at the same radial distance from the disk's axis of rotation. There is, of course an additional delay while data blocks are read from or written onto the disk surface.
The relative significance of disk latency has increased with recent dramatic improvements in computer processor speeds. Although there has also been some improvement in disk access times, the disk drive is still inherently limited in speed by its mechanical structure. A well known expedient that greatly reduces the number of disk accesses needed to run almost any software application, involves the use of a single common cache memory. The cache memory is usually a volatile random access memory (RAM) device, in which blocks of data read from a disk drive are stored for possible future use, and blocks of data to be written to the disk are temporarily stored to avoid an immediate disk operation. Whenever an application requests a disk read, the cache is first checked to see if the requested data block is already available. If so, a disk read operation is avoided. If not, the disk read operation is performed and the required block is transferred, given to the requesting application, and stored in the cache. When the cache is filled, new disk reads may result in having to remove blocks already in the cache. Removing blocks from the cache may be performed on any desired basis, such as keeping the most frequently used or most recently used blocks, or simply removing blocks on a first-in-first-out basis.
The same approach is not as easy to apply to disk write operations, because cached blocks not immediately written to the disk may be lost in the event of a power failure or some other condition that requires restarting the computer processor, or restarting a software system running on the computer. Therefore, the cache employs a "write through" procedure. When a disk write is requested, a memory block or blocks written into the cache are also immediately written onto the disk. When there is a read request, the cache is checked to determine if it contains an up to date version of each requested disk block. If the requested disk data is already cached, a disk read operation is avoided. However, the "write through" cache does not save any disk write operations.
A more recent innovation in this area is the use of a non-volatile random access memory (NVRAM) for disk caching. Because the contents of such a cache are not lost in the event of a power failure or similar catastrophic event, there is no need to perform disk writing immediately upon a request being made. Non-volatile disk caching prior to the present invention employed a simple "write behind" procedure, to write blocks of data to the disk only when the write cache is full. Thus, when the write cache becomes full, the write behind procedure decides which blocks to write to the disk. This decision is usually made on some reasonable basis, such as by choosing to write to the disk cylinder having the greatest number of "dirty" blocks in the write cache, or by choosing to write to the disk cylinder having the smallest seek distance (and access time). An example of a write caching scheme can be found in a paper by Jai Menon and Mike Hartung, entitled "The IBM 3990 Disk Cache," Proceedings of the IEEE Computer Society COMPCON Conference, 1988, pp. 146-51.
After dirty blocks are purged from the write cache by performing an actual disk write operation, they may be marked as "clean," which means that they are consistent with the data stored on the disk, and can be used to supply data for disk read operations.
In summary, there are three categories of prior disk caching systems: (a) single common cache with write through, (b) single common cache with write back, and (c) systems employing separate read and write caches. In the single common cache with write through, there are never any "dirty" blocks in the cache (because writes always go directly to the disk), but writes are costly in terms of overhead, since the cache is not effective for writes. The single common cache with write back reduces the number of writes to the disk, but there may be dirty blocks in the cache. A further difficulty is that the integrity of the disk data may be jeopardized in the event of a failure before the disk can be updated. Caching schemes using separate read and write caches are typified by the one described in the aforementioned paper by Menon et al. The system described in the paper apparently uses a volatile cache and a separate non-volatile (NV) write cache, but the write back policy is not specified.
A major disadvantage of the write behind procedure is that a disk write request initiated after the write cache is filled is stalled until the cache purge operation is completed and clean write cache blocks become available for use. Furthermore, if a write is initiated when the cache is filled and only a small amount of data is written in the interest of minimizing stall times, then many writes will frequently be needed, thus once again defeating the purpose of a write behind policy. Accordingly, it will be apparent that there is still a need for improvement in the field of disk caching techniques. In particular, what is needed is a write cache management technique that avoids the problems associated with the write behind procedure. The present invention satisfies this need and provides additional advantages.